import 'dart:async';

import 'package:flutter/material.dart';

class HeroBarWidget extends StatelessWidget {
  const HeroBarWidget({
    Key? key,
    this.onTap,
    this.count = 0,
    this.index = 0,
    this.reBuild,
  }) : super(key: key);

  final int count;
  final int index;
  final StreamController<int>? reBuild;
  final GestureTapCallback? onTap;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      bottom: false,
      child: Material(
        type: MaterialType.transparency,
        child: Container(
          width: double.infinity,
          child: Stack(
            children: [
              if (reBuild != null)
                StreamBuilder<int>(
                  builder: (BuildContext context, AsyncSnapshot<int> data) {
                    if (data.data == null) {
                      return SizedBox.shrink();
                    }
                    return Positioned.fill(
                      child: Center(
                        child: Text(
                          '${data.data! + 1}/$count',
                          style: Theme.of(context)
                              .textTheme
                              .titleMedium!
                              .copyWith(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                        ),
                      ),
                    );
                  },
                  initialData: index,
                  stream: reBuild!.stream,
                ),
              Material(
                color: Colors.transparent,
                shape: CircleBorder(),
                clipBehavior: Clip.hardEdge,
                child: IconButton(
                  onPressed: onTap,
                  icon: const Icon(
                    Icons.close,
                    color: Colors.white,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
